{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2a932eb3-f1f4-447e-9859-1dfa7003cb8f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "import datetime\n",
    "import pandas as pd\n",
    "import os\n",
    "\n",
    "def diff_month(d1, d2):\n",
    "    return abs((d1.year - d2.year) * 12 + d1.month - d2.month)\n",
    "\n",
    "def random_date():\n",
    "    return datetime.datetime(2021, 1, 1) + datetime.timedelta(days=random.randint(0,729))\n",
    "\n",
    "def random_buy_count(product):\n",
    "    buy_count = random.randint(1, 7)\n",
    "    month_count = diff_month(datetime.datetime(2021, 1, 1), product['销售日期'])\n",
    "    buy_count = int((1 + 0.1*month_count) * buy_count)\n",
    "        \n",
    "    product_type = product['类别']\n",
    "    hot_types = ['文具', '玩具', '书籍']\n",
    "    \n",
    "    if product_type in hot_types:\n",
    "        buy_count = buy_count + random.randint(0,7)\n",
    "    \n",
    "    return buy_count\n",
    "\n",
    "product_list = pd.read_excel(os.getcwd() + '\\产品清单.xlsx') \n",
    "\n",
    "def random_product():\n",
    "    product_id = random.randint(0, 27)\n",
    "    if product_id > 9:\n",
    "        product_id = random.randint(5,9)\n",
    "    \n",
    "    x = product_list.iloc[[product_id]]\n",
    "    return x.to_dict('records')[0]\n",
    "\n",
    "shop_list = ['街心花园店','育才小学店','咔咔广场店']\n",
    "\n",
    "def random_shop():\n",
    "    r = random.randint(0, 10)\n",
    "    if r <=5:\n",
    "        return shop_list[0]\n",
    "    elif r > 5 and r < 8:\n",
    "        return shop_list[1]\n",
    "    else:\n",
    "        return shop_list[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0e4bae75-9e82-49ac-9764-5eefcd5893b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "done.\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import datetime\n",
    "\n",
    "order_list = []\n",
    "\n",
    "# 起始日期\n",
    "start_date = datetime.datetime(2021, 1, 1)\n",
    "\n",
    "\n",
    "\n",
    "order_count = 30000\n",
    "\n",
    "for i in range(order_count):\n",
    "    product = random_product()\n",
    "    sale_date = random_date()\n",
    "    product['销售日期'] = sale_date\n",
    "    product['店铺'] = random_shop()\n",
    "    product['销售数量'] = random_buy_count(product)\n",
    "    \n",
    "    order_list.append(product)\n",
    "\n",
    "order_list_df = pd.DataFrame(order_list)\n",
    "    \n",
    "order_list_df.to_excel(os.getcwd() + '\\订单.xlsx', sheet_name='data', index=False)\n",
    "\n",
    "print('done.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18a3a88e-22dc-4e2d-a8a0-a012f70084dd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
